package com.zzyl.service.impl;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.mapper.DeviceDataMapper;
import com.zzyl.service.DeviceDataService;
import com.zzyl.utils.ObjectUtil;
import com.zzyl.vo.DeviceDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author sjqn
 * @date 2023/11/18
 */
@Service
public class DeviceDataServiceImpl implements DeviceDataService {

    @Autowired
    private DeviceDataMapper deviceDataMapper;

    /**
     * 查询设备数据
     * @param pageNum
     * @param pageSize
     * @param deviceName
     * @param functionId
     * @param startTime
     * @param endTime
     * @param status
     * @return
     */
    @Override
    public PageResponse<DeviceDataVo> getDeviceDataPage(Integer pageNum, Integer pageSize, String deviceName, String functionId, Long startTime, Long endTime, Integer status) {

        PageHelper.startPage(pageNum,pageSize);

        Page<DeviceDataVo> page = deviceDataMapper.page(status, deviceName, null, null, functionId,
                ObjectUtil.isEmpty(startTime) ? null : LocalDateTimeUtil.of(startTime), ObjectUtil.isEmpty(endTime) ? null : LocalDateTimeUtil.of(endTime));

        return PageResponse.of(page,DeviceDataVo.class);
    }
}
